Re: [INTERFACES] Creating a database with JDBC

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: [INTERFACES] Creating a database with JDBC
Дата
Msg-id l03110702b234fe941e28@[147.233.159.109]
обсуждение исходный текст
Ответ на Creating a database with JDBC  (Richard Heller <rheller@prime.cs.ohiou.edu>)
Список pgsql-interfaces
At 19:22 +0200 on 27/9/98, Richard Heller wrote:


> Is there any way to connect to the postgresql driver without having a
> database already in existence?  I want to have a Java program that can
> check if a database already exists and create the database if it doesn't
> exist.
>
> The examples I've seen all seem to assume that a database has already been
> created.

Not only for Java, but generally for Postgres: There is always a
"template1" database. That database gets created when you install Postgres.
If you want to issue database-manipulation commands in SQL, all you need to
do is to connect to "template1" as your database, and issue SQL commands
such as CREATE DATABASE.

If you want to detect whether a database exists, I think the information is
in one of the system catalogs, but I don't remember exactly which. Another
solution, of course, is to attempt to connect to it, and if the attempt
fails (should probably check what error message was returned), connect to
template1 and issue a CREATE DATABASE statement.

By the way, make sure your postgres server runs with the -i option, or you
won't be able to connect to it with Java.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-interfaces по дате отправления:

Предыдущее
От: "Stan Thomas"
Дата:
Сообщение: subscribe
Следующее
От: Peter T Mount
Дата:
Сообщение: Re: [INTERFACES] JDBC Connection refused